<template>
    <el-row>
        <el-col :xs="24" :sm="24" :lg="24">
            <div class="ibox">
                <div class="ibox-title">
                <h5>日数据汇总</h5> 
                </div>
                <div class="ibox-content">
                    <el-table
                        ref="filterTable"
                        :data="tableData"
                        style="width: 100%">
                        <el-table-column prop="update_time" label="日期" min-width="60"></el-table-column>
                        <el-table-column prop="count_patch" min-width="" label="Patch(个)"></el-table-column>
                        <el-table-column prop="lines_insert__sum" min-width="" label="代码新增(行)"></el-table-column>
                        <el-table-column prop="lines_delete__sum" min-width="" label="代码删除(行)"></el-table-column>
                        <el-table-column prop="inline_comments__sum" min-width="" label="代码评审注释(个)"></el-table-column>
                        <el-table-column prop="defect_density" min-width="100" label="评审缺陷密度(个/Kloc)"></el-table-column>
                        <el-table-column prop="effective_radio" min-width="" label="评审有效比率"></el-table-column>
                        <el-table-column prop="incorrect_inbound_code" min-width="" label="错误入库（个）"></el-table-column>
                        <el-table-column prop="invalid_association_set" min-width="" label="无效关联"></el-table-column>
                        <el-table-column fixed="right" label="操作" width="100">
                            <template slot-scope="scope">
                                <el-button type="text" size="small" @click="viewDetail(scope.$index, scope.row)">查看详情</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                    <el-pagination
                        style="padding-top: 10px;"
                        background
                        @current-change="handleCurrentChange"
                        :current-page="currentPage"
                        layout="total, prev, pager, next, jumper"
                        :total="total">
                    </el-pagination>
                </div>
            </div>
        </el-col>
    </el-row>  
</template>
<script>
import { mapState } from 'vuex'
import { getHeader } from '@/app.config';

export default {
    name: 'TableGerritDaily',
    // props: {
    //     filters: Object
    // },
    computed: {
        ...mapState({
            filters: state => state.filters
        })
    },
    data() {
        return {
            currentPage: 1,
            total: 0,
            tableData: [],
        }
    },
    watch: {
        filters: {
            handler: function() {
                this.currentPage = 1;
                this.getData(this.currentPage);
            },
            deep: true,
        },
    },
    methods: {
        getCodeReviewDaily(project, time, page) {            
            var project_name = this.filters.projectName//localStorage.getItem(project)
            var source = '/api/qa/projcodedaily?projectId=';
            source = source+project+'&time='+time+'&page='+page;
            this.$axios.get(source, {headers: getHeader()})
                .then((response) => {
                    if (response.status == 200) {
                        if (response.status == 200) {
                            if (response.data.code == 200) {
                                this.tableData = response.data.qSet;
                                this.total = response.data.count;
                            }
                        }
                    }
                })
                .catch((err) => {
                    // eslint-disable-next-line
                    console.log(err);
                });
        },
        getData: function(page) {           
            var time = this.filters.time;
            if (null == time || "undefined" == typeof(time)) {
                time = ''
            }
            this.getCodeReviewDaily(this.filters.projectId,time,page);
        },
        handleCurrentChange(val) {
            console.log(`当前页: ${val}`);
            this.currentPage = val;
            this.getData(this.currentPage);
        },
        viewDetail(index, row) {
			let routeData = this.$router.resolve({
				path:
					'/project/details/' +
					this.filters.projectId + '/' +
					this.filters.projectName +
					'_@_' +
					row.updatetime +
					'_@_gerrit'
			});
			window.open(routeData.href, '_blank');
		},
        goto_url_blank(row) {
            var daterange = row.updatetime;
            var branch = this.filters.select1;
            var component = this.filters.select2;
            if (component == '') {
                component = 'nullstring';
            }
            var url = '#/project/'+this.project_id +'/qa/qadetail/'+daterange+'&gerrit&'+branch+'&'+component
            window.open(url, "_blank");
        },
        formatter_rate(row, column, cellValue, index) {
            var str = Number(cellValue*100).toFixed(2);
            str += "%";
            return str;
        }
    },
    created: function() {
        // this.project_id = this.$route.params.pmsProjectId;
    },
    mounted: function() {
        this.getData(this.currentPage);
    }
}
</script>

<style lang="scss" scoped>
    @import '../../../assets/common/common.scss';
</style>
